Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add links and events to tracing payload #21

Merged
merged 8 commits into from
Jan 17, 2024
Merged

Conversation

ie-pham
Copy link
Contributor

@ie-pham ie-pham commented Dec 28, 2023

test outputs against tempo 3163

added "event attribute" in commit to verify changes took place during testing

trace json from querying trace by id

"events": [
  {
      "timeUnixNano": "1703790751493000000",
      "name": "k6.z82CnPfdkFVs",
      "attributes": [
          {
              "key": "event attributek6.qrbAb",
              "value": {
                  "stringValue": "k6.tZLSTRQUJzo8"
              }
          }
      ]
  }
],
"links": [
  {
      "traceId": "K43tbrFZhQRSPbpFbe6irw==",
      "spanId": "aZQKClAJ5tc=",
      "attributes": [
          {
              "key": "k6.lgCDAL7OExDN",
              "value": {
                  "stringValue": "k6.2W4d5oKDI7nq"
              }
          }
      ]
  }
],

Screenshot 2023-12-28 at 1 15 44 PM

@CLAassistant
Copy link

CLAassistant commented Dec 28, 2023

CLA assistant check
All committers have signed the CLA.

@stoewer
Copy link
Collaborator

stoewer commented Dec 28, 2023

The PR looks good. However, it would be great to have some more capabilities regarding links

  • By default the xk6-client-tracing docker image runs the script ./examples/template/template.js which uses the TemplatedGenerator and not the ParameterizedGenerator. Therefore it would be nice to add the possibility to send links to the TemplatedGenerator too
  • It would be useful if there was a parameter to tune the link generation in the ParameterizedGenerator

@ie-pham ie-pham self-assigned this Jan 4, 2024
@ie-pham ie-pham changed the title add links Add links and events to tracing payload Jan 4, 2024
Copy link
Contributor

@zalegrala zalegrala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Nice addition.

Copy link
Collaborator

@stoewer stoewer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR. I suggested a couple of changes to make the new functionality more consistent with the existing behavior

{service: "shop-backend", attributes: {"http.status_code": 403}},
{service: "shop-backend", name: "authenticate", attributes: {"http.request.header.accept": ["application/json"]}},
{service: "auth-service", name: "authenticate", attributes: {"http.status_code": 403}},
{service: "test-random", name: "events", randomEvents: {exceptionCount: 1, count: 2, randomAttributes: {count: 5, cardinality: 2}}},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this template the span and service names etc. mimic traces from a somewhat plausible e-commerce service landscape. It would be good to keep this and choose less generic service (test-random) and span names (links, events) here

RandomAttributes *AttributeParams `js:"randomAttributes"`
}

type LinkDefaults struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For randomly generated attributes the struct is called AttributeParams and it is used in SpanTemplate and SpanDefaults. Do you think we can do the same for links i.e. merge LinkDefaults and RandomLinks to LinkParams? If you use Rate instead of Count it should be possible to merge LinkDefaults and RandomLinks into one struct without losing functionality.

The main advantage beside consistency is that users don't have to remember two similar sets of parameters and where to use which one.

type LinkDefaults struct {
// LinkToPreviousSpanIndex true will set TraceID and SpanID the same as the previous span
// Unless it is the first span then a random TraceID and a random SpanID will be used
LinkToPreviousSpanIndex bool `js:"linkToPreviousSpanIndex"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we could make true the default for all links and remove this option. The reason is that this option is very specific and does not leave much room for future changes in the linking behavior without making this option obsolete. Maybe we want to link across traces in the future or link to random siblings in the same trace ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. will just make it link to the previous span as the default until we can support linking to specific trace/span in the future

RandomAttributes *AttributeParams `js:"randomAttributes"`
}

type EventDefaults struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for links about merging EventDefaults and RandomEvents to EventParams

RandomAttributes: defaults.EventDefaults.RandomAttributes,
Count: int(eventDefaultsRate),
}
} else if idx%int(1/eventDefaultsRate) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to use a random factor instead of the index to decide whether to add an event. The condition could look like this: random.Float() < eventDefaultsRate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

RandomAttributes: defaults.LinkDefaults.RandomAttributes,
Count: int(linkDefaultsRate),
}
} else if idx%int(1/linkDefaultsRate) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment as for events: consider using a random factor instead of the index

Comment on lines 53 to 56
// Random events generated for each span
EventDefaults EventDefaults `js:"eventDefaults"`
// Random links generated for each span
LinkDefaults LinkDefaults `js:"linkDefaults"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to RandomEvents and RandomLinks in order to be more consistent with the existing RandomAttributes

@ie-pham ie-pham requested a review from stoewer January 15, 2024 23:03
randomAttributes: {count: 2, cardinality: 5}
randomAttributes: {count: 2, cardinality: 5},
eventDefaults: {generateExceptionOnError: true, count: 1.0, randomAttributes: {count: 2, cardinality: 3}},
linkDefaults: {linkToPreviousSpanIndex: true, count: 1.0, randomAttributes: {count: 2, cardinality: 3}},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was not adjusted to the latest changes

Comment on lines 55 to 57
EventDefaults EventParams `js:"eventDefaults"`
// Random links generated for each span
LinkDefaults LinkParams `js:"linkDefaults"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to RandomEvents and RandomLinks in order to be consistent with RandomAttributes and field names in SpanTemplate

{service: "shop-backend", name: "authenticate", attributes: {"http.request.header.accept": ["application/json"]}},
{service: "auth-service", name: "authenticate", attributes: {"http.status_code": 403}},
{service: "cart-service", name: "checkout", randomEvents: {exceptionCount: 1, count: 2, randomAttributes: {count: 5, cardinality: 2}}},
{service: "billing-service", name: "payment", randomLinks: {linkToPreviousSpanIndex: true, count: 2, randomAttributes: {count: 3, cardinality: 2}}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was also not updated to the latest changes

{service: "shop-backend", attributes: {"http.status_code": 403}},
{service: "shop-backend", name: "authenticate", attributes: {"http.request.header.accept": ["application/json"]}},
{service: "auth-service", name: "authenticate", attributes: {"http.status_code": 403}},
{service: "cart-service", name: "checkout", randomEvents: {exceptionCount: 1, count: 2, randomAttributes: {count: 5, cardinality: 2}}},
Copy link
Collaborator

@stoewer stoewer Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I test this together with the changes in PR grafana/tempo#3163 the events look a bit odd.

  • The timestamp is a negative value. In the trace data returned by tempo the timestamp is zero.
  • Instead of an event name with the value "exception" there is a field message with the value {"Type": "STRING", "Value": "exception"}

TBH I'm not sure about the origin of those problems. Maybe there is also a front-end issue?

image

Copy link
Contributor Author

@ie-pham ie-pham Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh weird, I am using grafana/grafana:main and I do see message instead of name but it just shows "exception" not a struct

I did notice that if timestamp is not provided, the front-end will display a negative number

tempo:latest
Screenshot 2024-01-16 at 1 06 32 PM
Screenshot 2024-01-16 at 1 06 40 PM
Screenshot 2024-01-16 at 1 07 21 PM

tempo:pr3163
Screenshot 2024-01-16 at 1 10 55 PM
Screenshot 2024-01-16 at 1 11 30 PM
Screenshot 2024-01-16 at 1 11 39 PM

@ie-pham
Copy link
Contributor Author

ie-pham commented Jan 16, 2024

I pushed my latest changes:

  • rename EventDefaults => RandomEvents, LinkDefaults => RandomLinks
  • add timestamp to exceptions
  • fix the example template

@ie-pham ie-pham merged commit e340ce8 into grafana:main Jan 17, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants